<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<form name="myForm" action="https://www.baidu.com/s">
	<input autocomplete="off" name="wd" type="text">
	<button>搜索</button>
</form>
<div id="root"></div>
<script src="lib/jsonp.js"></script>
<script>
	const root = document.querySelector("#root");
	document.myForm.wd.oninput = function () {
		jsonp({
			//https://www.baidu.com/sugrec?prod=pc&wd=三国&cb=xxxx
			// 地址
			url: "https://www.baidu.com/sugrec",
			// 查询对象，最终会被转为字符串
			params:{
				prod:"pc",
				wd:this.value.trim()
			},
			jsonp:"cb",
			success(res){
				if (res.q) {
					root.innerHTML = res.g.map(item => (`
					<p>${item.q}</p>
				`)).join("");
				} else root.innerHTML = null;
			}
		})
	}
</script>
</body>
</html>